package com.tongqu.mapper;


import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface JumpDataDao {


    @Insert({
            "<script>"+
                    "insert into  t_game_jump(source_appId,target_appId,type,count,time) " +
                    "values" +
                    "<foreach collection= 'result'  item='item'  index='index' separator=','>" +
                    "(#{item.sourceAppId}, #{item.targetAppId},#{item.type},#{item.count},#{item.time})" +
                    "</foreach>" +
                    "</script>"
    })
    public int saveData(@Param("result") List dataList);
    @Delete("truncate t_game_jump")
    int clearAllData();

    @Insert("insert into t_data SELECT source_appId ,  target_appId,visit_count ,click_count , TIME FROM( SELECT t1.source_appId , t1.target_appId ,t1.count AS click_count,0 AS visit_count , DATE(t1.time) AS TIME FROM t_game_jump AS t1 WHERE t1.`type`='click' UNION ALL SELECT t2.source_appId , t2.target_appId ,0 AS click_count ,t2.count AS visit_count , DATE(t2.`time`) AS TIME FROM t_game_jump AS t2 WHERE t2.`type`='visit') AS t")
    int saveDataIntoTempData();

    @Delete("truncate t_data")
    int clearData();
}
